{extend name='public/base' /}
{block name='content'}
{include file='public/content_header' /}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <!-- 表单头部 -->
                <div class="box-header with-border">
                    <div class="btn-group">
                        <a class="btn flat btn-sm btn-default BackButton">
                            <i class="fa fa-arrow-left"></i>
                            返回
                        </a>
                    </div>
                </div>
                <!-- 表单 -->
                <form id="dataForm" class="form-horizontal dataForm" action="" method="post"
                      enctype="multipart/form-data">
                    <!-- 表单字段区域 -->
                    <div class="box-body">
                        <div class="form-group">
                            <label for="avatar" class="col-sm-2 control-label">照片</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="avatar" name="avatar" placeholder="请上传照片" type="file"
                                class="form-control field-image" data-initial-preview="{$data.avatar|default=''}" >
                            </div>
                        </div>
                        <script>
                            $('#avatar').fileinput({
                                language: 'zh',
                                overwriteInitial: true,
                                browseLabel: '浏览',
                                initialPreviewAsData: true,
                                dropZoneEnabled: false,
                                showUpload: false,
                                showRemove: false,
                                allowedFileTypes: ['image'],
                                maxFileSize: 10240,
                            });
                        </script>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">姓名</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="name" name="name" value="{$data.name|default=''}" placeholder="请输入姓名"
                                       type="text" class="form-control field-text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="department_id" class="col-sm-2 control-label">部门</label>
                            <div class="col-sm-10 col-md-4">
                                <select name="department_id" id="department_id" class="form-control field-select"
                                        data-placeholder="请选择部门">
                                    <option value=""></option>
                                    {$department_list|raw}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('#department_id').select2();
                        </script>
                        <div class="form-group">
                            <label for="position_id" class="col-sm-2 control-label">职位</label>
                            <div class="col-sm-10 col-md-4">
                                <select name="position_id" id="position_id" class="form-control field-select"
                                        data-placeholder="请选择职位">
                                    <option value=""></option>
                                    {foreach name='position_list' id='item'}
                                    <option value="{$item.id}" {if isset($data) &&
                                            $data.position_id==$item.id}selected{/if}>
                                        {$item.name}
                                    </option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <script>
                            $('#position_id').select2();
                        </script>
                        <div class="form-group">
                            <label for="job_number" class="col-sm-2 control-label">工号</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="job_number" name="job_number" value="{$data.job_number|default='0'}"
                                       placeholder="请输入工号" type="text" class="form-control field-text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="mobile" class="col-sm-2 control-label">手机号</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="mobile" name="mobile" value="{$data.mobile|default=''}" placeholder="请输入手机号"
                                       type="tel" maxlength="11" class="form-control field-mobile">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="email" class="col-sm-2 control-label">邮箱</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="email" name="email" value="{$data.email|default=''}" placeholder="请输入邮箱"
                                       type="email" class="form-control field-email">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="birthday" class="col-sm-2 control-label">生日</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="birthday" name="birthday" value="{$data.birthday|default=''}"
                                       placeholder="请选择生日" type="text" class="form-control filed-date">
                            </div>
                        </div>
                        <script>
                            laydate.render({
                                elem: '#birthday',
                            });
                        </script>
                        <div class="form-group">
                            <label for="hired_date" class="col-sm-2 control-label">入职日期</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="hired_date" name="hired_date" value="{$data.hired_date|default=''}"
                                       placeholder="请选择入职日期" type="text" class="form-control filed-date">
                            </div>
                        </div>
                        <script>
                            laydate.render({
                                elem: '#hired_date',
                            });
                        </script>
                        <div class="form-group">
                            <label for="is_boss" class="col-sm-2 control-label">是否为老板</label>
                            <div class="col-sm-10 col-md-4">
                                <input class="input-switch" id="is_boss" value="1" {if(!isset($data) ||$data.is_boss==1)}checked{/if} type="checkbox"/>
                                <input class="switch field-switch" placeholder="是否为老板" name="is_boss"
                                       value="{$data.is_boss|default='0'}" hidden/>
                            </div>
                        </div>

                        <script>
                            $('#is_boss').bootstrapSwitch({
                                onText: "是",
                                offText: "否",
                                onColor: "success",
                                offColor: "danger",
                                onSwitchChange: function (event, state) {
                                    $(event.target).closest('.bootstrap-switch').next().val(state ? '1' : '0').change();
                                }
                            });
                        </script>
                        <div class="form-group">
                            <label for="is_leader" class="col-sm-2 control-label">是否所属部门领导</label>
                            <div class="col-sm-10 col-md-4">
                                <input class="input-switch" id="is_leader" value="1" {if(!isset($data)
                                       ||$data.is_leader==1)}checked{/if} type="checkbox"/>
                                <input class="switch field-switch" placeholder="是否所属部门领导" name="is_leader"
                                       value="{$data.is_leader|default='0'}" hidden/>
                            </div>
                        </div>

                        <script>
                            $('#is_leader').bootstrapSwitch({
                                onText: "是",
                                offText: "否",
                                onColor: "success",
                                offColor: "danger",
                                onSwitchChange: function (event, state) {
                                    $(event.target).closest('.bootstrap-switch').next().val(state ? '1' : '0').change();
                                }
                            });
                        </script>
                        <div class="form-group">
                            <label for="sort_number" class="col-sm-2 control-label">排序</label>
                            <div class="col-sm-10 col-md-4">
                                <input id="sort_number" name="sort_number" value="{$data.sort_number|default='1000'}"
                                       placeholder="请输入排序" type="text" class="form-control field-text">
                            </div>
                        </div>

                    </div>
                    <!-- 表单底部 -->
                    <div class="box-footer">
                        {:token()}
                        <div class="col-sm-2">
                        </div>
                        <div class="col-sm-10 col-md-4">
                            {if !isset($data)}
                            <div class="btn-group pull-right">
                                <label class="createContinue">
                                    <input type="checkbox" value="1" id="_create" name="_create"
                                           title="继续添加数据">继续添加</label>
                            </div>
                            {/if}
                            <div class="btn-group">
                                <button type="submit" class="btn flat btn-info dataFormSubmit">
                                    保存
                                </button>
                            </div>
                            <div class="btn-group">
                                <button type="reset" class="btn flat btn-default dataFormReset">
                                    重置
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<script>
    /** 表单验证 **/
    $('#dataForm').validate({
        rules: {
            'name': {
                required: true,
            },
            'department_id': {
                required: true,
            },
            'position_id': {
                required: true,
            },
            'job_number': {
                required: true,
            },
            'mobile': {
                required: true,
            },
            'email': {
                required: true,
            },
            'birthday': {
                required: true,
            },
            'hired_date': {
                required: true,
            },
            'is_boss': {
                required: true,
            },
            'is_leader': {
                required: true,
            },
            'sort_number': {
                required: true,
            },

        },
        messages: {
            'name': {
                required: "姓名不能为空",
            },
            'department_id': {
                required: "部门不能为空",
            },
            'position_id': {
                required: "职位不能为空",
            },
            'job_number': {
                required: "工号不能为空",
            },
            'mobile': {
                required: "手机号不能为空",
            },
            'email': {
                required: "邮箱不能为空",
            },
            'birthday': {
                required: "生日不能为空",
            },
            'hired_date': {
                required: "入职日期不能为空",
            },
            'is_boss': {
                required: "是否为老板不能为空",
            },
            'is_leader': {
                required: "是否所属部门领导不能为空",
            },
            'sort_number': {
                required: "排序不能为空",
            },

        }
    });
</script>
{/block}